<template>
	<div>
		<Header></Header>
		<el-row class="content" v-loading="loading">
			<h2 class="title">{{$t('media.imageManage')}}</h2>
			<el-row class="search-form-row">
				<el-form :inline="true" ref="searchForm">
					<el-form-item :label="$t('persons.company')">
						<el-select v-model="companyId" @change="query(1)">
							<el-option v-for="company in companyList" :key="company.id" :value="company.id" :label="company.value"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item :label="$t('persons.type1')" label-width="120px">
						<!-- 这里 下拉框里绑定的值是一个对象  必须在select里设置 value-key="id" -->
						<el-select v-model="type_query" @change="query(1)" style="width: 90%;">
							<el-option value="">{{$t('persons.whole')}}</el-option>
							<el-option v-for="type in typeList" :key="type.value" :label="type.label" :value="type.value"></el-option>
						</el-select>
					</el-form-item>

					<!--<el-form-item>
                        <el-button type="primary" @click="query(1)">{{$t('standard.query')}}</el-button>
                    </el-form-item>-->
					<el-form-item>
						<el-button type="primary" @click="addMedia">{{$t('media.newPicture')}}</el-button>
					</el-form-item>
				</el-form>
			</el-row>
			<el-row>
				<el-row v-show="showImage">
					<ul style="height: auto;padding: 0;margin: 0 0 10px 25px;">
					</ul>
					<div class="ih-media" v-for="item in mediaData" :key="item.id">
						<a href="#">
							<div class="img">
								<img v-bind:src="item.mediaType == 0 ? item.mediaPath : item.capturePath" alt="img" :style="item.style"
								 :onerror="errorImg">
							</div>
							<div class="info" style="line-height: 100px">
								<h3 @click="showVideo(item.mediaPath, item.mediaType, item.capturePath)">
									{{item.mediaName}}</h3>
								<a class="el-icon-edit" style="color: #4D9EFC; font-size: 18px" @click="modMedia(item)" :title="$t('standard.modify')"></a>
								&nbsp;&nbsp;&nbsp;&nbsp;
								<a class="el-icon-delete" style="color: rgba(255, 0, 0, 0.6); font-size: 18px" @click="delDialog(item.id)"
								 :title="$t('standard.delete')"></a>
							</div>
						</a>
					</div>
				</el-row>
				<div v-if="mediaData.length == 0" class="el-table__empty-block"><span class="el-table__empty-text">暂无数据</span></div>
				<el-row v-else style="text-align: center;margin-top: 10px">
					<img src="../../assets/load-more.png" style="cursor: pointer; width: 300px" @click="pageInfo.currentPage += 1;query(pageInfo.currentPage)" />
				</el-row>
			</el-row>

			<el-dialog :title="formTitle" :visible.sync="playVisible" width="30%" @close="closeDialog">
				<video-player class="video-player vjs-custom-skin" ref="videoPlayer" :playsinline="true" :options="playerOptions"
				 @ready="playerReadied" @loadeddata="onPlayerLoadeddata($event)"></video-player>
			</el-dialog>
			<el-dialog :title="mediaTitle" :visible.sync="mediaVisible" :show-close="false" width="600px">
				<el-row>
					<el-form :model="addForm" :rules="addRules" ref="addForm" label-width="120px" style="text-align: left">
						<el-form-item :label="$t('media.pictureName')" prop="mediaName" style="width: 500px">
							<el-input v-model="addForm.mediaName" auto-complete="off" style="width: 217px;" maxlength="20"></el-input>
							<el-upload class="upload-demo" v-if="!modDisabled" style="float: right; width: 100px" :action="uploadPath"
							 accept="image/*" :on-change="handleUploadChange" :before-upload="beforeUpload" :show-file-list="false"
							 :on-progress="uploadVideoProcess" :on-success="afterUpload" :on-error="errorUpload">
								<el-button type="primary" round>{{$t('media.uploadPictures')}}</el-button>
							</el-upload>
						</el-form-item>
						<el-form-item :label="$t('media.bindingAttachment')" prop="type" style="width: 500px">
							<el-select v-model="addForm.type" style="width: 217px;" @change="changeType">
								<el-option v-for="type in typeList" :key="type.value" :label="type.label" :value="type.value"></el-option>
							</el-select>
							<el-upload class="upload-demo" v-if="addForm.type === '1' || addForm.type === '2'" style="float: right; width: 100px"
							 :action="uploadPath" :accept="extAccept" :on-change="handleUploadChange" :before-upload="beforeUpload"
							 :show-file-list="false" :on-progress="uploadVideoProcess" :on-success="extAfterUpload" :on-error="errorUpload">
								<el-button type="primary" round>{{$t('media.uploadAttachments')}}
									<!-- 附件说明（<span style="font-size: 10px" v-html="fileSuffix">mp3、wav</span>）-->
								</el-button>
							</el-upload>
						</el-form-item>
						<el-form-item v-if="addForm.type === '0'" :label="$t('media.textContent')" prop="mediaContent">
							<el-input type="textarea" v-model="addForm.mediaContent" auto-complete="off" style="width: 217px;" maxlength="50"></el-input>
						</el-form-item>
					</el-form>
					<p class="tl">{{$t('text.text1')}}
						<br>{{$t('text.text2')}}
						<br>{{$t('text.text3')}}
						<br>{{$t('text.text4')}}
					</p>
				</el-row>
				<span slot="footer" class="dialog-footer">
					<el-button @click="mediaVisible = false">{{$t('standard.cancel')}}</el-button>
					<el-button type="primary" @click="subPicForm" :loading="saving">{{$t('standard.confirm')}}</el-button>
				</span>
			</el-dialog>

			<el-dialog :title="$t('standard.prompt')" :visible.sync="mediaDelVisible" width="400px" :show-close="false">
				<span>{{$t('message.DDData')}}</span>
				<span slot="footer" class="dialog-footer">
					<el-button @click="mediaDelVisible = false">{{$t('standard.cancel')}}</el-button>
					<el-button type="primary" @click="delMedia">{{$t('standard.confirm')}}</el-button>
				</span>
			</el-dialog>

			<el-dialog :title="$t('message.fileUploading')" :visible.sync="processVisible" width="35%" top="20px">
				<span>{{$t('text.text5')}}</span>
				<el-progress type="line" :percentage="videoUploadPercent" style="margin-top:30px;"></el-progress>
			</el-dialog>
		</el-row>
	</div>
</template>

<script>
	import media from './media'


	export default media;
</script>

<style>
	.tl {
		text-align: left;
	}

	.search-form-row {
		text-align: left;
	}

	.portlet {
		clear: both;
		margin-top: 0px;
		margin-bottom: 25px;
		padding: 0px;
	}

	.portlet-title {
		margin-bottom: 15px;
		border-bottom: 1px solid #eee;
	}

	.portlet-title .caption {
		float: left;
		display: inline-block;
		font-size: 18px;
		font-weight: 400;
		margin: 0;
		padding: 0;
		margin-bottom: 7px;
	}

	table th {
		background-color: #f9f9f9;
	}

	table th,
	table td {

		text-align: left;
		padding: 8px;
	}

	.ih-media {
		position: relative;
		width: 350px;
		height: 350px;
		float: left;
		margin-left: 40px;
		margin-bottom: 40px;
		background: url(../../assets/media_bg.png);
		background-repeat: no-repeat;
		background-size: 100% 100%;
	}

	.ih-media .img img {
		position: absolute;
		min-width: 100%;
		min-height: 100%;
		display: block;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		/*object-fit:cover;*/
	}

	.ih-media .img {
		overflow: hidden;
		width: 350px;
		height: 350px;
		position: relative;
	}

	.ih-media .info {
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		text-align: center;
		-webkit-backface-visibility: hidden;
		/* 隐藏旋转元素的背面*/
		backface-visibility: hidden;
		background: rgba(0, 0, 0, 0.6);
		/*后面这个0.6是指的背景的透明度*/
		opacity: 0;
		-webkit-transition: all 0.35s ease-in-out;
		/*规定提示信息怎样出现ease-in-out以慢速度开始和结束*/
		-moz-transition: all 0.35s ease-in-out;
		transition: all 0.35s ease-in-out;
		border-radius: 8px;
		color: #ffffff;
	}

	.ih-media a:hover .info {
		opacity: 1;
		/*有opacity有0变成1*/
	}
</style>
